Skip to content

⚡ Improve EditorBeatmap.findInsertionIndex performance using binary search - #86

Merged
winnerspiros merged 1 commit into
masterfrom
improve-editorbeatmap-performance-18417970512521063628
Feb 21, 2026
Merged

⚡ Improve EditorBeatmap.findInsertionIndex performance using binary search#86
winnerspiros merged 1 commit into
masterfrom
improve-editorbeatmap-performance-18417970512521063628

Conversation

@google-labs-jules

Copy link
Copy Markdown

💡 What

Replaced the linear search implementation in EditorBeatmap.findInsertionIndex with a binary search algorithm.

🎯 Why

The findInsertionIndex method is called when adding hit objects or tracking their start time changes. With a large number of hit objects (e.g., 10,000+), the linear search (O(N)) becomes a bottleneck during bulk operations or frequent updates. Binary search (O(log N)) significantly reduces the complexity.

📊 Measured Improvement

A benchmark was created to measure the performance of findInsertionIndex with 100, 1,000, and 10,000 hit objects.

Count Linear (Baseline) Binary (Optimized) Improvement
100 162.1 ns 27.44 ns ~6x
1,000 1,626.3 ns 38.05 ns ~42x
10,000 41,592.5 ns 49.87 ns ~834x

For 10,000 objects, the operation is over 800 times faster.

The optimization maintains the original behavior: finding the index of the last element with StartTime <= targetTime.

Tests passed:

  • osu.Game.Tests.Visual.Editing.TestSceneEditorBeatmap
  • osu.Game.Tests.Editing.TestSceneEditorBeatmapProcessor
  • osu.Game.Tests.Editing.LegacyEditorBeatmapPatcherTest
  • osu.Game.Tests.Visual.Editing.TestSceneEditorBeatmapCreation

PR created automatically by Jules for task 18417970512521063628 started by @winnerspiros

Replaces the O(N) linear search with O(log N) binary search for finding insertion indices.
Benchmarks show up to ~834x improvement for 10,000 hit objects.

| Count | Linear | Binary |
|-------|--------|--------|
| 100   | 162 ns | 27 ns  |
| 1000  | 1.6 us | 38 ns  |
| 10000 | 41 us  | 49 ns  |
@google-labs-jules

Copy link
Copy Markdown
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@winnerspiros
winnerspiros merged commit 7eabf41 into master Feb 21, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant